package com.sanyang.lawyer.controller.finance;

import com.sanyang.lawyer.entity.*;
import com.sanyang.lawyer.service.Case.Case_lawService;
import com.sanyang.lawyer.service.Case.Case_typeService;
import com.sanyang.lawyer.service.finance.Finance_payService;
import com.sanyang.lawyer.service.finance.Finance_payoutService;
import com.sanyang.lawyer.service.finance.Finance_payout_typeService;
import com.sanyang.lawyer.service.hr.HrEmpService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestController;

import java.util.*;

/**
 * @program: lawyer
 * @description: 支出
 * @author: lql
 * @create: 2019-10-14 19:23
 **/
@RestController
@RequestMapping("financePayoutController")
public class FinancePayoutController {

        @Autowired
        //收支类型
        private Finance_payout_typeService finance_payout_typeService;
        @Autowired
        //案件类型Service
        private Case_typeService case_typeService;
        @Autowired
        //支付类型
        private Finance_payService finance_payService;
        //个人支出表
        @Autowired
        private Finance_payoutService finance_payoutService;
        //案号
        @Autowired
        private Case_lawService case_lawService;
        //emp表
        @Autowired
        private HrEmpService hrEmpService;

        //收支类型遍历
        @RequestMapping("payouttypelist")
        @ResponseBody
        public List<Finance_payout_type> payouttypelist(){
            List<Finance_payout_type> list=finance_payout_typeService.getbypid();
            List<Finance_payout_type> list1=new ArrayList<Finance_payout_type>();
            List<Finance_payout_type> list2=new ArrayList<Finance_payout_type>();
            List<Finance_payout_type> list3=new ArrayList<Finance_payout_type>();
            for(int i=0;i<list.size();i++){
                list1.add(list.get(i));
                list2=finance_payout_typeService.getbychild(list.get(i).getPayoutTypeId());
                for(int j=0;j<list2.size();j++) {
                    list1.add(list2.get(j));
                    list3=finance_payout_typeService.getbychild(list2.get(j).getPayoutTypeId());
                    for(int n=0;n<list3.size();n++){
                        list1.add(list3.get(n));
                    }
                }
            }
            return list1;
        }
        //案件类型遍历
        @RequestMapping("caseid")
        @ResponseBody
        public List<Case_type> caseid(){
            List<Case_type> list=case_typeService.queryParent();
            List<Case_type> list1=new ArrayList<Case_type>();
            List<Case_type> list2=new ArrayList<Case_type>();
            for(int i=0;i<list.size();i++){
                list1.add(list.get(i));
                list2=case_typeService.queryParent_children(list.get(i).getCaseTypeid());
                for(int j=0;j<list2.size();j++){
                    list1.add(list2.get(j));
                }
            }
            return list1;
        }
        //支付方式类型
        @RequestMapping("paytype")
        @ResponseBody
        public List<Finance_pay> paytype(){
            List<Finance_pay> list=finance_payService.list();
            return list;
        }


        //个人支出遍历
        @RequestMapping("payoutlist")
        @ResponseBody
        public List<Finance_payout> payoutlist(int paytype,int caseId,int payoutType,String inputdate,String enteringdate,String cookie,String caselawid){
            Map<String,String> map=seleclist(paytype,caseId,payoutType,inputdate,enteringdate,cookie,caselawid);
            List<Finance_payout> list=finance_payoutService.list(map);
            if(list.size()==0){
                return null;
            }else {
                return list;
            }
        }

        //模糊查询
        public Map<String,String> seleclist(int paytype,int caseId,int payoutType,String inputdate,String enteringdate,String cookie,String caselawid){
            Map<String,String> map=new HashMap<String,String>();
            map.put("caseid",Integer.toString(caseId));
            map.put("paytype",Integer.toString(paytype));
            map.put("payoutType",Integer.toString(payoutType));
            map.put("inputdate",inputdate);
            map.put("enteringdate",enteringdate);
            map.put("cookie",cookie);
            map.put("caselawid",caselawid);
            return map;
        }

        //案号
        @RequestMapping("caselawlist")
        @ResponseBody
        public List<Case_law> caselawlist(String name,String sel){
            Map<String,String> map=new HashMap<String,String>();
            map.put("name",name);
            map.put("sel",sel);
            List<Case_law> list=case_lawService.listalls(map);
            return list;
        }

        //案件查询
        @RequestMapping("casequery")
        @ResponseBody
        public List<Case_law> casequery(String casetext,String  casequery){
            Map<String,String> map=new HashMap<String, String>();
            if(casetext!=""&&casetext!=null){
                switch (casequery){
                    case "1":
                        String casetext1=null;
                        casetext1=casetext;
                        map.put("casetext1",casetext1);  //案号
                        break;
                    case "2":
                        String casetext2=null;
                        casetext2=casetext;
                        map.put("casetext2",casetext2);  //承办律师
                        break;
                    case "3":
                        String casetext3=null;
                        casetext3=casetext;
                        map.put("casetext3",casetext3);  //委托人
                        break;
                    case "4":
                        String casetext4=null;
                        casetext4=casetext;
                        map.put("casetext4",casetext4);  //当事人
                        break;
                    case "5":
                        String casetext5=null;
                        casetext5=casetext;
                        map.put("casetext5",casetext5);  //案由
                        break;
                    case "6":
                        String casetext6=null;
                        casetext6=casetext;
                        map.put("casetext6",casetext6);  //受理法院
                        break;
                }
            }
            List<Case_law> list=case_lawService.casequery(map);
            return list;
        }

        //收支添加
        @RequestMapping("addpayout")
        @ResponseBody
        public int add(Case_law caseId,String enteringDate, String inoutMoney, Finance_payout_type payoutTypeId, Finance_pay  payId, String payer, String inoutPerson, String remark){
            Map<String,String> map=new HashMap<String,String>();
            map.put("caseId",caseId.getCaseId());
            map.put("enteringDate",enteringDate);
            map.put("inoutMoney",inoutMoney);
            map.put("payoutTypeId",payoutTypeId.getPayoutTypeId()+"");
            map.put("payId",payId.getPayId()+"");
            map.put("payer",payer);
            map.put("inoutPerson",inoutPerson);
            map.put("remark",remark);
            map.put("inoutDate",enteringDate);
            System.out.println(map);
            int i=finance_payoutService.add(map);
            return i;
        }
        //收支人
        @RequestMapping("incomepayer")
        @ResponseBody
        public List<Hr_emp> empname(String empName){
            List<Hr_emp> emp=hrEmpService.getByEmpName(empName);
            if(emp.size()==0){
                return null;
            }else {
                return emp;
            }
        }

        //删除收支明细
        @RequestMapping("delete")
        @ResponseBody
        public int delete(int payoutId){
            int i=finance_payoutService.delete(payoutId);
            return i;
        }

        //根据name查询收支类型
        @RequestMapping("payname")
        @ResponseBody
        public Finance_payout_type payname(String name){
            Finance_payout_type payname=finance_payout_typeService.getbyname(name);
            return payname;
        }
}
